<?php
class TicketItemModel {
    private $ticket_item_id;
    private $ticket_id;
    private $item_id;
    private $service_name;
    private $payment_type;
    private $room_id;
    private $room_name;
    private $item_type;
    private $status;
    private $queue_id;

    function __construct($ticketItemId = '', $ticketId = '', $itemId = '', $serviceName = '', $paymentType = '', $roomId = '', $roomName = '', $itemType = '', $status = '', $queueId = '') {
        $this->ticket_item_id   =   $ticketItemId;
        $this->ticket_id        =   $ticketId;
        $this->item_id          =   $itemId;
        $this->service_name     =   $serviceName;
        $this->payment_type     =   $paymentType;
        $this->room_id          =   $roomId;
        $this->room_name        =   $roomName;
        $this->item_type        =   $itemType;
        $this->status           =   $status;
        $this->queue_id         =   $queueId;
    }

    public function getTicketItemId() {
    	return $this->ticket_item_id;
    }

    public function getServiceName() {
    	return $this->service_name;
    }

    public function getStatus() {
    	return $this->status;
    }

    public function getItemType() {
        return $this->item_type;
    }

    public function getQueueId(){
    	return $this->queue_id;
    }

    public function getRoomName(){
    	return $this->room_name;
    }
    // General setter
    public function set($key, $value) {
        if(property_exists($this,$key)){
            $this->$key =   $value;
        }
    }

    // General getter
    public function get($key) {
        if(property_exists($this,$key)){
            return $this->$key;
        }
        return '';
    }

    // Populate data from an array
    public function populateArray($data) {
    	foreach ($data as $key => $value) {
            $this->set($key, $value);
    	}
    }

    public function setup($ticketItemId) {
        $objTicketItem  =   Celini::newORDO('TicketItem', $ticketItemId);
        $itemType       =   $objTicketItem->get('item_type');
        switch ($itemType){
        	case TicketItem::SERVICE_TYPE:
        		$data =   $objTicketItem->getServiceItem($ticketItemId);
        		break;
        	case TicketItem::COMPOSITE_SERVICE:
        		$data =   $objTicketItem->getCompositeItem($ticketItemId);
        		break;
            case TicketItem::TEST_TYPE:
                $data =   $objTicketItem->getLabItem($ticketItemId);
                break;
            case TicketItem::ENDO_TYPE:
            case TicketItem::XRAY_TYPE:
            case TicketItem::ULTRA_TYPE:
            	$data =   $objTicketItem->getRadItem($ticketItemId);
            	break;
            default:
            	$data  =   array();
            	break;
        }
        $this->populateArray($data);
        $objQueueItem   =   ORDataObject::factory('QueueItem')->fromTicketItemId($ticketItemId);
        $this->queue_id =   $objQueueItem->get('queue_id');
    }
}
?>